home *** CD-ROM | disk | FTP | other *** search
- /* C Extender - ClipDemo2 */
- /* Aztec C compiler 1.06g */
-
- /* David A. Feldt 2/27/86 */
- /* David A. Feldt 3/18/86 */
- /* David A. Feldt found maintain cursor bug 3/19/86 */
- /* David A. Feldt fixed bugs and added digitron lines 3/20/86 */
- /* Joseph Sitomer added calls to math. model stuff 3/24/86 */
- /* David A. Feldt removed journal window and code 5/16/86 */
- /* David A. Feldt added terminal code to MICOR window 5/18/86 */
-
- #include "clipinclude.h"
-
-
- main()
- {
- int i;
-
- ClipInit(); /* Clip specific initialize routine */
- TermInit(); /* init data structures, menus and windows */
-
- do {
- do {
- if (micor == TRUE) {
- CheckPort(); /* take care of data arriving at comm port */
- }
- SystemTask(); /* slice of cpu time to desk accessories*/
- } while (!GetNextEvent(everyEvent,&Event)); /* repeat until event */
- HandleEvent(&Event,&whatHappened); /* get event info from extender */
-
- if (whatHappened.MenuNum > 0) {
- HndlMenus(&whatHappened);
- }
- if (whatHappened.WhichControl != NULL) {
- HndlCntrls(&whatHappened);
- }
- if (whatHappened.WhichWindow == dWindPtr && digitron == TRUE && Event.what == mouseDown) {
- HndlDig(&whatHappened,&Event);
- }
- if (micor == TRUE) {
- HndlChar(LoWord(Event.message));
- }
-
- } while (!(whatHappened.MenuH == fileMenu && whatHappened.ItemNum == 12));
- }
-
- void HndlDig(ES,EV)
- EventStuff *ES;
- EventRecord *EV;
- {
- Point pt;
- Rect tRect;
- INT width = apRect.right - apRect.left;
- INT height = apRect.top - apRect.bottom;
- char string[16];
- INT apxo = apRect.left + (width / 2);
- INT apyo = apRect.top - (height / 2);
- INT latxo = latRect.left + (width / 2);
- INT latyo = latRect.top - (height / 2);
-
-
-
- if (ES->WindowPart == inContent) {
- SetPort(dWindPtr);
- pt = EV->where;
- GlobalToLocal(&pt);
- if (PtInRect(pass(pt),&apRect)) {
- SetRect(&tRect,pt.h,pt.v,pt.h + 2,pt.v + 2);
- FrameOval(&tRect);
-
- ptvect0[0] = (FLOAT)(pt.h - apxo);
- ptvect0[1] = (FLOAT)(pt.v - apyo);
- ptvect0[2] = (FLOAT)(APDMAX - distAP);
- mxmul(aptopat,3,3,ptvect0,3,1,ptvectt);
- ptvect0[0] = ptvectt[0];
- ptvect0[1] = ptvectt[1];
- ptvect0[2] = ptvectt[2];
- mxmul(pattolat,3,3,ptvect0,3,1,ptvectt);
- mf = MagFact(ptvectt[2],(LATDMAX - distLAT));
- ptvectt[0] *= mf;
- ptvectt[1] *= mf;
-
- fsvect0[0] = 0;
- fsvect0[1] = 0;
- fsvect0[2] = -ISOCTOFS;
- mxmul(aptopat,3,3,fsvect0,3,1,fsvectt);
- fsvect0[0] = fsvectt[0];
- fsvect0[1] = fsvectt[1];
- fsvect0[2] = fsvectt[2];
- mxmul(pattolat,3,3,fsvect0,3,1,fsvectt);
- mf = MagFact(fsvectt[2],(LATDMAX - distLAT));
- fsvectt[0] *= mf;
- fsvectt[1] *= mf;
-
- ClipRect(&latRect);
- MoveTo((INT)(latxo + ptvectt[0]),(INT)(latyo + ptvectt[1]));
- LineTo((INT)(latxo + fsvectt[0]),(INT)(latyo + fsvectt[1]));
- ClipRect(&(dWindPtr->portRect));
- }
- else
- if (PtInRect(pass(pt),&latRect)) {
- SetRect(&tRect,pt.h,pt.v,pt.h + 2,pt.v + 2);
- FrameOval(&tRect);
-
- ptvect0[0] = (FLOAT)(pt.h - latxo);
- ptvect0[1] = (FLOAT)(pt.v - latyo);
- ptvect0[2] = (FLOAT)(LATDMAX - distLAT);
- mxmul(lattopat,3,3,ptvect0,3,1,ptvectt);
- ptvect0[0] = ptvectt[0];
- ptvect0[1] = ptvectt[1];
- ptvect0[2] = ptvectt[2];
- mxmul(pattoap,3,3,ptvect0,3,1,ptvectt);
- mf = MagFact(ptvectt[2],(APDMAX - distAP));
- ptvectt[0] *= mf;
- ptvectt[1] *= mf;
-
- fsvect0[0] = 0;
- fsvect0[1] = 0;
- fsvect0[2] = -ISOCTOFS;
- mxmul(lattopat,3,3,fsvect0,3,1,fsvectt);
- fsvect0[0] = fsvectt[0];
- fsvect0[1] = fsvectt[1];
- fsvect0[2] = fsvectt[2];
- mxmul(pattoap,3,3,fsvect0,3,1,fsvectt);
- mf = MagFact(fsvectt[2],(APDMAX - distAP));
- fsvectt[0] *= mf;
- fsvectt[1] *= mf;
-
- ClipRect(&apRect);
- MoveTo((INT)(apxo + ptvectt[0]),(INT)(apyo + ptvectt[1]));
- LineTo((INT)(apxo + fsvectt[0]),(INT)(apyo + fsvectt[1]));
- ClipRect(&(dWindPtr->portRect));
- }
- }
-
- }
-
- DOUBLE MagFact(zobj,zisoc)
- DOUBLE zobj;
- INT zisoc;
- {
- return ((DOUBLE) (zisoc + ISOCTOFS) / ((DOUBLE) ISOCTOFS + zobj));
- }
-
-
- void HndlCntrls(ES)
- EventStuff *ES;
- {
- if (ES->WhichWindow == BWindPtr)
- HndlBICOR(ES);
- }
-
- void HndlBICOR(ES)
- EventStuff *ES;
- {
- char string[16];
- long value;
-
- if (ES->WhichControl == apcntrls[0]) {
- value = (long)GetCtlVal(apcntrls[0]);
- NumToString(value - APAMIN,string);
- SetCTitle(apcntrls[3],string);
- rotAlphAP(value - APAMIN);
- }
- if (ES->WhichControl == apcntrls[1]) {
- value = (long)GetCtlVal(apcntrls[1]);
- NumToString(value - APBMIN,string);
- SetCTitle(apcntrls[4],string);
- rotBetaAP(value - APBMIN);
- }
- if (ES->WhichControl == apcntrls[2]) {
- value = (long)GetCtlVal(apcntrls[2]);
- NumToString(APDMAX - value,string);
- SetCTitle(apcntrls[5],string);
- distAP = value;
- }
- if (ES->WhichControl == apcntrls[6]) {
- rotAlphAP(0);
- rotBetaAP(0);
- distAP = 0;
- NumToString((long)alphaAP,string);
- SetCTitle(apcntrls[3],string);
- SetCtlValue(apcntrls[0],alphaAP + APAMIN);
- NumToString((long)betaAP,string);
- SetCTitle(apcntrls[4],string);
- SetCtlValue(apcntrls[1],betaAP + APBMIN);
- NumToString((long)(APDMAX - distAP),string);
- SetCTitle(apcntrls[5],string);
- SetCtlValue(apcntrls[2],distAP);
- }
- if (ES->WhichControl == latcntrls[0]) {
- value = (long)GetCtlVal(latcntrls[0]);
- NumToString(value - LATAMIN,string);
- SetCTitle(latcntrls[3],string);
- rotAlphLAT(value - LATAMIN);
- }
- if (ES->WhichControl == latcntrls[1]) {
- value = (long)GetCtlVal(latcntrls[1]);
- NumToString(value - LATBMIN,string);
- SetCTitle(latcntrls[4],string);
- rotBetaLAT(value - LATBMIN);
- }
- if (ES->WhichControl == latcntrls[2]) {
- value = (long)GetCtlVal(latcntrls[2]);
- NumToString(LATDMAX - value,string);
- SetCTitle(latcntrls[5],string);
- distLAT = value;
- }
- if (ES->WhichControl == latcntrls[6]) {
- rotAlphLAT(0);
- rotBetaLAT(0);
- distLAT = 0;
- NumToString((long)alphaLAT,string);
- SetCTitle(latcntrls[3],string);
- SetCtlValue(latcntrls[0],alphaLAT + LATAMIN);
- NumToString((long)betaLAT,string);
- SetCTitle(latcntrls[4],string);
- SetCtlValue(latcntrls[1],betaLAT + LATBMIN);
- NumToString((long)(LATDMAX - distLAT),string);
- SetCTitle(latcntrls[5],string);
- SetCtlValue(latcntrls[2],distLAT);
- }
- mkmxa(alphaAP,betaAP,aptopat,pattoap);
- mkmxl(alphaLAT,betaLAT,lattopat,pattolat);
- mkmxii(pattoap,aptopat,pattolat,lattopat,aptolat,lattoap);
- return();
- }
-
- void rotAlphAP(value)
- long value;
-
- {
- if (alphaAP < (INT) value) {
- for ( ; alphaAP <= (INT) value; alphaAP += ((value - alphaAP > 5) ? 5 : 1))
- drawAParcs();
- alphaAP -= 1;
- }
- else if (alphaAP > (INT) value) {
- for ( ; alphaAP >= (INT) value; alphaAP -= ((alphaAP - value > 5) ? 5 : 1))
- drawAParcs();
- alphaAP += 1;
- }
- }
-
- void rotBetaAP(value)
- long value;
-
- {
- if (betaAP < (INT) value) {
- for (; betaAP <= (INT) value; betaAP += ((value - betaAP > 5) ? 5 : 1))
- drawAParcs();
- betaAP -= 1;
- }
- else if (betaAP > (INT) value) {
- for (; betaAP >= (INT) value; betaAP -= ((betaAP - value > 5) ? 5 : 1))
- drawAParcs();
- betaAP += 1;
- }
- }
-
- void rotAlphLAT(value)
- long value;
-
- {
- if (alphaLAT < (INT) value) {
- for (; alphaLAT <= (INT) value; alphaLAT += (value - alphaLAT > 5) ? 5 : 1)
- drawLATarcs();
- alphaLAT -= 1;
- }
- else if (alphaLAT > (INT) value) {
- for (; alphaLAT >= (INT) value; alphaLAT -= (alphaLAT - value > 5) ? 5 : 1)
- drawLATarcs();
- alphaLAT += 1;
- }
- }
-
- void rotBetaLAT(value)
- long value;
-
- {
- if (betaLAT < (INT) value) {
- for (; betaLAT <= (INT) value; betaLAT += (value - betaLAT > 5) ? 5 : 1)
- drawLATarcs();
- betaLAT -= 1;
- }
- else if (betaLAT > (INT) value) {
- for (; betaLAT >= (INT) value; betaLAT -= (betaLAT - value > 5) ? 5 : 1)
- drawLATarcs();
- betaLAT += 1;
- }
- }
-
-
- WindowPtr MkBICORWindow(tlcorner)
- Point tlcorner;
- {
- Rect tempRect;
- WindowPtr wPtr;
- char string[16];
-
- SetRect(&tempRect,tlcorner.h,tlcorner.v,tlcorner.h + 350,tlcorner.v + 300);
- wPtr = CreateWindow(&BICORWind,&tempRect,"\PBICOR window",16,TRUE,TRUE,FALSE,FALSE,FALSE);
- SetRect(&tempRect,10,125,90,141);
- apcntrls[0] = CreateScrollBar(wPtr,&tempRect,alphaAP + APAMIN,0,APAMIN + APAMAX);
- SetRect(&tempRect,160,125,240,141);
- apcntrls[1] = CreateScrollBar(wPtr,&tempRect,betaAP + APBMIN,0,APBMIN + APBMAX);
- SetRect(&tempRect,117,20,133,80);
- apcntrls[2] = CreateScrollBar(wPtr,&tempRect,distAP,0,APDMAX - APDMIN);
- SetRect(&tempRect,30,105,70,121);
- NumToString((long)alphaAP,string);
- apcntrls[3] = CreatePushButton(wPtr,&tempRect,string);
- SetRect(&tempRect,180,105,220,121);
- NumToString((long)betaAP,string);
- apcntrls[4] = CreatePushButton(wPtr,&tempRect,string);
- SetRect(&tempRect,110,90,140,106);
- NumToString((long)(APDMAX - distAP),string);
- apcntrls[5] = CreatePushButton(wPtr,&tempRect,string);
- SetRect(&tempRect,270,20,330,40);
- apcntrls[6] = CreatePushButton(wPtr,&tempRect,"\PHome AP");
- SetRect(&tempRect,270,50,330,70);
- apcntrls[7] = CreatePushButton(wPtr,&tempRect,"\PProg #1");
- SetRect(&tempRect,270,80,330,100);
- apcntrls[8] = CreatePushButton(wPtr,&tempRect,"\PProg #2");
- SetRect(&tempRect,270,110,330,130);
- apcntrls[9] = CreatePushButton(wPtr,&tempRect,"\PProg #3");
- /* lat controls definitions */
- SetRect(&tempRect,10,275,90,291);
- latcntrls[0] = CreateScrollBar(wPtr,&tempRect,alphaLAT + LATAMIN,0,LATAMIN + LATAMAX);
- SetRect(&tempRect,160,275,240,291);
- latcntrls[1] = CreateScrollBar(wPtr,&tempRect,betaLAT + LATBMIN,0,LATBMIN + LATBMAX);
- SetRect(&tempRect,117,170,133,230);
- latcntrls[2] = CreateScrollBar(wPtr,&tempRect,distLAT,0,LATDMAX - LATDMIN);
- SetRect(&tempRect,30,255,70,271);
- NumToString((long)alphaLAT,string);
- latcntrls[3] = CreatePushButton(wPtr,&tempRect,string);
- SetRect(&tempRect,180,255,220,271);
- NumToString((long)betaLAT,string);
- latcntrls[4] = CreatePushButton(wPtr,&tempRect,string);
- SetRect(&tempRect,110,240,140,256);
- NumToString((long)(LATDMAX - distLAT),string);
- latcntrls[5] = CreatePushButton(wPtr,&tempRect,string);
- SetRect(&tempRect,270,170,330,190);
- latcntrls[6] = CreatePushButton(wPtr,&tempRect,"\PHomeLAT");
- SetRect(&tempRect,270,200,330,220);
- latcntrls[7] = CreatePushButton(wPtr,&tempRect,"\PProg #1");
- SetRect(&tempRect,270,230,330,250);
- latcntrls[8] = CreatePushButton(wPtr,&tempRect,"\PProg #2");
- SetRect(&tempRect,270,260,330,280);
- latcntrls[9] = CreatePushButton(wPtr,&tempRect,"\PProg #3");
- return(wPtr);
- }
-
- void ClipInit()
- {
- XTendInit(); /* extender initialization routine */
- StdMenus(&appleMenu,&fileMenu,&editMenu); /* set up standard menus */
- toolMenu = BuildMenu(20,"\PTools","\PBICOR;MICOR;Digitron");
- digitron = FALSE;
- Bicor = FALSE;
- EnableItem(appleMenu,1);
- ShowAboutBox();
- BICORValInit();
- }
-
- void BICORValInit()
- {
- alphaAP = 0;
- betaAP = 0;
- distAP = 0;
- alphaLAT = 0;
- betaLAT = 0;
- distLAT = 0;
-
- mkmxa(alphaAP,betaAP,aptopat,pattoap);
- mkmxl(alphaLAT,betaLAT,lattopat,pattolat);
- mkmxii(aptopat,pattoap,lattopat,pattolat,aptolat,lattoap);
- }
-
- void HndlMenus(ES)
- EventStuff *ES;
- {
- WData WD;
- int i;
- static int bauds[] = {0x17c, 0xbd, 0x5e, 0x3e, 0x2e, 0x1e, 0x16, 0x0e, 0x0a, 0x04};
-
- switch (ES->MenuNum) {
- case 11: /* APPLE menu */
- if (ES->ItemNum == 1)
- ShowAboutBox();
- break;
- case 20: /* TOOLS menu */
- switch (ES->ItemNum) {
- case 1: /* BICOR option */
- if (Bicor == FALSE)
- InitBICOR();
- else
- KillBICOR();
- break;
- case 2: /* MICOR option */
- if (micor == FALSE)
- InitMicor();
- else
- KillMicor();
- break;
- case 3: /* Digitron option */
- if (digitron == FALSE)
- InitDigitron();
- else
- KillDigitron();
- break;
- }
- break;
- case 21: /* if the Baud menu was selected */
- for (i=1;i<11;i++) /* remove checks on all items */
- CheckItem(baudMenu, i, 0);
- CheckItem(baudMenu,whatHappened.ItemNum,TRUE);/* check the item selected*/
- Port->baud = bauds[whatHappened.ItemNum - 1]; /* set port baud rate */
- setupport(); /* reinitialize port settings */
- break;
- case 22: /* if the Port menu was selected */
- CheckItem(portMenu, 1, 0);
- CheckItem(portMenu, 2, 0);
- switch(whatHappened.ItemNum) {
- case 1:
- switchport(&PortA);
- CheckItem(portMenu, 1, TRUE);
- break;
- case 2:
- switchport(&PortB);
- CheckItem(portMenu, 2, TRUE);
- break;
- }
- break;
- }
- }
-
- void InitMicor()
- {
- if (micor == FALSE) {
- ShowWindow(mWindPtr);
- SelectWindow(mWindPtr);
- SetPort(mWindPtr);
- micor = TRUE;
- }
- }
-
- void KillMicor()
- {
- if (micor == TRUE) {
- HideWindow(mWindPtr);
- micor = FALSE;
- }
- }
-
- void PicBICOR()
- {
- PicHandle picHndl;
- Rect R;
-
- picHndl = OpenPicture(&(screenBits.bounds));
-
- SetRect(&R,5,5,95,95);
- FrameOval(&R);
-
- SetRect(&R,155,5,245,95);
- FrameOval(&R);
-
- SetRect(&R,5,155,95,245);
- FrameOval(&R);
-
- SetRect(&R,155,155,245,245);
- FrameOval(&R);
-
- SetRect(&R,260,10,340,290);
- FrameRoundRect(&R,16,16);
-
- MoveTo(110,125);
- DrawString("\PAP arm");
- MoveTo(105,275);
- DrawString("\PLAT arm");
- ClosePicture();
- SetPort(BWindPtr);
- DrawPicture(picHndl,&(screenBits.bounds));
- SetWPic(BWindPtr,picHndl);
- drawAParcs();
- drawLATarcs();
- }
-
- void drawAParcs()
- {
- Rect R;
- DOUBLE sinb,cosb;
- INT height;
-
- cosb = cos((DOUBLE) betaAP * Pi / 180.0);
- sinb = sin((DOUBLE) betaAP * Pi / 180.0);
- height = (INT) 25.0 * cosb;
-
- SetRect(&R,25,25,75,75);
- EraseRect(&R);
- PenSize(3,3);
- if (height >= 0) {
- if (height < 3) height = 3;
- SetRect(&R,25,50 - height,75, 50 + height);
- FrameArc(&R,alphaAP + 180,180);
- }
- else {
- if (height > -3) height = -3;
- SetRect(&R,25,50 + height,75, 50 - height);
- FrameArc(&R,180 - alphaAP,180);
- }
-
- SetRect(&R,172,22,228,78);
- EraseRect(&R);
- MoveTo(200 + (INT) (25.0 * sinb),50 + (INT) (25.0 * cosb));
- LineTo(200 - (INT) (25.0 * sinb),50 - (INT) (25.0 * cosb));
- PenSize(1,1);
- }
-
- void drawLATarcs()
-
- {
- Rect R;
- DOUBLE sinb,cosb;
- INT width;
-
- cosb = cos((DOUBLE) betaLAT * Pi / 180.0);
- sinb = sin((DOUBLE) betaLAT * Pi / 180.0);
- width = (INT) 25.0 * cosb;
-
- SetRect(&R,25,175,75,225);
- EraseRect(&R);
- PenSize(3,3);
- SetRect(&R,50 - width,175,50 + width,225);
- FrameArc(&R,alphaLAT + 270,180);
-
- SetRect(&R,172,172,228,228);
- EraseRect(&R);
- MoveTo(200 + (INT) (25.0 * cosb),200 + (INT) (25.0 * sinb));
- LineTo(200 - (INT) (25.0 * cosb),200 - (INT) (25.0 * sinb));
- PenSize(1,1);
- }
-
-
- void HandleUpdateException (wPtr)
-
- WindowPtr wPtr;
-
- {
-
- GrafPtr tempport;
-
- GetPort (&tempport);
- SetPort(wPtr);
- BeginUpdate (wPtr);
- GrafUpdate (&(wPtr->portRect),wPtr);
- DrawControls (wPtr);
- drawAParcs();
- drawLATarcs();
- EndUpdate(wPtr);
- SetPort(tempport);
- }
-
-
- void InitBICOR()
- {
- Point corner;
-
- if (Bicor == FALSE) {
- corner.h = 30; /* setpoint topleft */
- corner.v = 50;
- BWindPtr = MkBICORWindow(pass(corner));
- SetUpdateException(BWindPtr,TRUE);
- PicBICOR();
- Bicor = TRUE;
- }
- }
-
- void KillBICOR()
- {
- if (Bicor == TRUE) {
- KillWindow(BWindPtr);
- Bicor = FALSE;
- }
- }
-
- void InitDigitron()
- {
- Rect WRect;
- Rect tempRect;
- PicHandle tempPic;
- char string[16];
-
- ptvect0[0] = ptvect0[1] = ptvect0[2] = 0.;
- ptvectt[0] = ptvectt[1] = ptvectt[2] = 0.;
- fsvect0[0] = fsvect0[1] = fsvect0[2] = 0.;
- fsvectt[0] = fsvectt[1] = fsvectt[2] = 0.;
- if (digitron == FALSE) {
- SetRect(&WRect,60,110,360,310); /* set rect topleft & bottomright */
- dWindPtr = CreateWindow(&dWind,&WRect,"\PDigitron window",0,TRUE,TRUE,FALSE,FALSE,FALSE);
- SetPort(dWindPtr);
- tempPic = OpenPicture(&(screenBits.bounds));
- SetRect(&apRect,10,10,110,110);
- SetRect(&latRect,130,10,230,110);
- FrameRect(&apRect);
- FrameRect(&latRect);
- MoveTo(40,130);
- DrawString("\PAP view");
- MoveTo(160,130);
- DrawString("\PLAT view");
- ClosePic();
- DrawPicture(tempPic,&(screenBits.bounds));
- SetWPic(dWindPtr,tempPic);
- digitron = TRUE;
- }
- }
-
- void KillDigitron()
- {
- if (digitron == TRUE) {
- KillWindow(dWindPtr);
- digitron = FALSE;
- }
- }
-
- void UserGoAway(theWindow)
- WindowPtr theWindow;
- {
- if ((micor == TRUE) && (theWindow == mWindPtr)) {
- KillMicor();
- return();
- }
- if ((digitron == TRUE) && (theWindow == dWindPtr)) {
- KillDigitron();
- return();
- }
- if ((Bicor == TRUE) && (theWindow == BWindPtr)) {
- KillBICOR();
- return();
- }
- }
-
- void ShowAboutBox()
- {
- DialogPtr DP;
- int itemHit;
-
- DP = GetNewDialog(128,NULL,NEG_ONE); /* 'About' dialog was assigned #128 */
- ShowWindow(DP);
- ModalDialog(NULL,&itemHit);
- DisposDialog(DP);
- }
-
- INT UserArrowInc(w,c,a)
- WindowPtr w;
- ControlHandle c;
- INT a;
- {
- INT temp;
-
- if (w == BWindPtr) {
- temp = (GetCtlMax(c) - GetCtlMin(c)) / 100 + 1;
- return(temp);
- }
- }
-
- INT UserPageInc(w,c,p)
- WindowPtr w;
- ControlHandle c;
- INT p;
- {
- INT temp;
-
- if (w == BWindPtr) {
- temp = (GetCtlMax(c) - GetCtlMin(c)) / 10 + 1;
- return(temp);
- }
- }
-